package com.hlw.hr_man.daoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.hlw.hr_man.dao.DaleteDeptDao;
import com.hlw.hr_man.util.JDBCUtil;

public class DaleteDeptDaoImpl implements DaleteDeptDao{

	@Override
	public int daleteDept(int dept_id) {
		int flag = 0;
		Connection con = JDBCUtil.getConnection();
		StringBuffer sql = new StringBuffer("update hr_department set dept_isdel=1 where dept_id =?");
		try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			pst.setInt(1, dept_id);
			int i = pst.executeUpdate();
			if(i>0){
				flag = 1;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return flag;
	}

	@Override
	public int selectEmployee(int dept_id) {
		int flag = 0;
		Connection con = JDBCUtil.getConnection();
		StringBuffer sql = new StringBuffer("select hr_employee.e_name from hr_department, hr_employee where hr_department.dept_id =hr_employee.dept_id and hr_department.dept_id=?");
        try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			pst.setInt(1, dept_id);
			ResultSet rs = pst.executeQuery();
			if(rs.next()){
				flag =1;//查询不到返回flag为1
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
		return flag;
	}

}
